local skels = {}

local liewu = fk.CreateSkill{
    name = "xiaobai__liewu"
}
Fk:loadTranslationTable{
    ["xiaobai__liewu"] = "烈忤",
    [":xiaobai__liewu"] = "每轮限一次，你的牌响应其他角色使用的黑色牌后，你可以弃置任意张类别不同的牌对其造成X点伤害，其因此进入濒死状态时，其可以回复至X点体力并令你摸X张牌（X为你弃置的牌数）。",
    ["xiaobai__liewu_active"] = "烈忤",
    ["#xiaobai__liewu"] = "烈忤：你可以弃置任意张类别不同的牌，并对 %dest 造成等量伤害",
    ["#xiaobai__liewu-recover"] = "烈忤：是否回复%arg点体力，并令 %dest 摸等量张牌",
}
local spec = {
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(liewu.name) and player:usedSkillTimes(liewu.name, Player.HistoryRound) == 0 and
        data.responseToEvent and data.responseToEvent.from and data.responseToEvent.from ~= player and data.responseToEvent.from:isAlive() and
        data.responseToEvent.card and data.responseToEvent.card.color == Card.Black
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local bool, dat = room:askToUseActiveSkill(player, {
            skill_name = "xiaobai__liewu_active",
            prompt = "#xiaobai__liewu::"..data.responseToEvent.from.id,
            skip = true,
        })
        if bool and dat then
            event:setCostData(self, {cards = dat.cards})
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local cards = event:getCostData(self).cards
        local current = data.responseToEvent.from
        room:throwCard(cards, liewu.name, player, player)
        if current.dead then return end
        room:damage{
            damage = #cards,
            to = current,
            from = player,
            skillName = liewu.name,
            extra_data = {
                xiaobai__liewu_num = #cards,
                xiaobai__liewu_player = player,
            }
        }
    end,
}
liewu:addEffect(fk.CardUseFinished, spec)
liewu:addEffect(fk.CardRespondFinished, spec)
liewu:addEffect(fk.EnterDying, {
    can_refresh = function(self, event, target, player, data)
        return data.damage and data.damage.skillName == liewu.name and
        data.damage.extra_data and data.damage.extra_data.xiaobai__liewu_player == player
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        local num = data.damage.extra_data.xiaobai__liewu_num
        if room:askToSkillInvoke(target, {
            skill_name = liewu.name,
            prompt = "#xiaobai__liewu-recover::"..player.id..":"..num
        }) then
            room:recover{
                who = target,
                num = num,
                skillName = liewu.name
            }
            if not player.dead then
                player:drawCards(num, liewu.name)
            end
        end
    end,
})
table.insert(skels, liewu)

local liewu_active = fk.CreateSkill{
    name = "xiaobai__liewu_active",
}
liewu_active:addEffect("active", {
    min_card_num = 0,
    target_num = 0,
    target_filter = Util.FalseFunc,
    card_filter = function (self, player, to_select, selected, selected_targets)
        if not player:prohibitDiscard(to_select) then
            if #selected == 0 then
                return true
            else
                local types = {}
                for _, cardID in ipairs(selected) do
                    table.insert(types, Fk:getCardById(cardID).type)
                end
                return not table.contains(types, Fk:getCardById(to_select).type)
            end
        end
    end,
})
table.insert(skels, liewu_active)

return skels